/**
 * @param {number} n
 * @return {boolean}
 */
var isHappy = function(n) {
  let set = new Set();
  set.add(n);
  let num = n.toString();
  while(!set.has(num)) {
    set.add(num);
    let temp = 0;
    for(let i = 0; i < num.length; i++) {
      temp += parseInt(num[i]) * parseInt(num[i]);
    }
    num = temp.toString();
    if(num == 1)
      return true;
  }
  return false;
};
let n = 19;
console.log(isHappy(n));
n = 2;
console.log(isHappy(n));
